<?php

namespace app\admin\controller;

use app\admin\model\BankModel;
use app\admin\model\CarModel;
use app\admin\model\DriverModel;
use my\Security;
use think\Db;
use think\Env;
use my\Tools;
use app\admin\model\RegionModel;
use app\admin\model\AdminModel;
use app\admin\controller\ProduceCode;

class InterRoute extends Base
{
    //protected  $map = ['auth_status'=>1];//只显示通过审核的司机

    protected $driver_model;

    public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub

    }

    //司机列表
    public function index()
    {
        $page = input('get.page');
        $limit = input('get.limit');
        $driver_type = input('get.driver_type');
        if ($page && $limit) {
            $where=$this->mapData;

            $start = ($page - 1) * $limit;
            $list = Db::name('route_info a')
                ->join('their b', 'a.their_id = b.their_id', 'LEFT')
                ->join('driver d', 'a.driver_id = d.driver_id', 'LEFT')
                ->limit($start, $limit)
                ->where($where)
                ->order('create_time desc')
                ->select();
            $count = Db::name('route_info a')
                ->join('their b', 'a.their_id = b.their_id', 'LEFT')
                ->join('driver d', 'a.driver_id = d.driver_id', 'LEFT')
                ->where($where)->count();
            foreach ($list as $key => $value) {
                $list[$key]['route_price'] = number_format($value['route_price']/100,2);
                $list[$key]['route_status_name'] = $value['route_status']==1?'启用中':'已关闭';
                $list[$key]['create_time'] = !empty($value['create_time']) ? date("Y-m-d H:i", $value['create_time']) : '-';

            }

            echo json_encode(array(
                'code' => 0,
                'msg' => '',
                'count' => $count,
                'data' => $list
            ));
            exit;
        }

        $this->assign('driver_type', $driver_type);
        return view();
    }
    //****详情
    public function detail() {
        $route_id        = input('get.route_id');
        //查询用户信息
        $where=$this->mapData;
        $where['a.route_id']=$route_id;
        $list = Db::name('route_info a')
            ->join('their b', 'a.their_id = b.their_id', 'LEFT')
            ->join('driver d', 'a.driver_id = d.driver_id', 'LEFT')
            ->where($where)
            ->order('create_time desc')
            ->find();
        $list['route_price'] = number_format($list['route_price']/100,2);
        $list['route_status'] = $list['route_status']==1?'启用中':'已关闭';
        $list['create_time'] = !empty($list['create_time']) ? date("Y-m-d H:i", $list['create_time']) : '-';

        $this->assign('routeInfo', $list);
        return $this->fetch();
    }
    //****关闭路线1启用2关闭
    public function forbid_info() {
        $route_id        = input('post.route_id');
        //查询用户信息
        $orderUP['route_status']=2;
        $res = Db::name('route_info')->where("route_id=$route_id")->update($orderUP);
        if($res){
            return json(['code' => 1, 'msg' => '操作成功']);
        }else{
            return json(['code'=>2,'msg'=>'参数错误']);
        }

    }
    //****启用路线1启用2关闭
    public function ajax_forbid() {
        $route_id        = input('post.route_id');
        //查询用户信息
        $orderUP['route_status']=1;
        $res = Db::name('route_info')->where("route_id=$route_id")->update($orderUP);
        if($res){
            return json(['code' => 1, 'msg' => '操作成功']);
        }else{
            return json(['code'=>2,'msg'=>'参数错误']);
        }

    }

}
